package com.sjgs.gis.service;

import com.sjgs.gis.domain.NodePlugin;
import com.sjgs.gis.repository.NodePluginRepository;
import com.sjgs.gis.service.dto.NodePluginDTO;
import com.sjgs.gis.service.mapper.NodePluginMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Optional;

/**
 * Service Implementation for managing {@link NodePlugin}.
 */
@Service
@Transactional
public class NodePluginService {

    private final Logger log = LoggerFactory.getLogger(NodePluginService.class);

    private final NodePluginRepository nodePluginRepository;

    private final NodePluginMapper nodePluginMapper;

    public NodePluginService(NodePluginRepository nodePluginRepository, NodePluginMapper nodePluginMapper) {
        this.nodePluginRepository = nodePluginRepository;
        this.nodePluginMapper = nodePluginMapper;
    }

    /**
     * Save a nodePlugin.
     *
     * @param nodePluginDTO the entity to save.
     * @return the persisted entity.
     */
    public NodePluginDTO save(NodePluginDTO nodePluginDTO) {
        log.debug("Request to save NodePlugin : {}", nodePluginDTO);
        NodePlugin nodePlugin = nodePluginMapper.toEntity(nodePluginDTO);
        nodePlugin = nodePluginRepository.save(nodePlugin);
        return nodePluginMapper.toDto(nodePlugin);
    }

    /**
     * Get all the nodePlugins.
     *
     * @param pageable the pagination information.
     * @return the list of entities.
     */
    @Transactional(readOnly = true)
    public Page<NodePluginDTO> findAll(Pageable pageable) {
        log.debug("Request to get all NodePlugins");
        return nodePluginRepository.findAll(pageable)
            .map(nodePluginMapper::toDto);
    }


    /**
     * Get one nodePlugin by id.
     *
     * @param id the id of the entity.
     * @return the entity.
     */
    @Transactional(readOnly = true)
    public Optional<NodePluginDTO> findOne(Long id) {
        log.debug("Request to get NodePlugin : {}", id);
        return nodePluginRepository.findById(id)
            .map(nodePluginMapper::toDto);
    }

    /**
     * Delete the nodePlugin by id.
     *
     * @param id the id of the entity.
     */
    public void delete(Long id) {
        log.debug("Request to delete NodePlugin : {}", id);
        nodePluginRepository.deleteById(id);
    }
}
